<!DOCTYPE html>
<html>
<head>
    <title>注册页面</title>
    <style>
        .td_left {
            width: 100px;
            height: 45px;
            text-align: right;
        }
        .td_right {
            padding-left: 50px;
        }
		/* 【评审意见】这种实现方式很不好。可以用input标签做选择器。 */
        .fillet {
            width: 251px;
            height: 32px;
            border: 1px solid #A6A6A6;
            /* 设置边框圆角 */
            border-radius: 5px;
            padding-left: 10px;
        }
        #btn_sub{
            width: 150px;
            height: 40px;
            background-color: #FFD026;
            border: 1px solid #FFD026 ;
        }
    </style>
</head>
<body>
<div class="rg_center">
    <form action="#" onsubmit="return check()">
        <table>
            <tr>
                <td class="td_left"><label for="username">用户名</label></td>
                <td class="td_right"><input type="text" name="username" class="fillet" placeholder="请输入用户名"></td>
            </tr>
            <tr>
                <td class="td_left"><label for="password">密码</label></td>
                <td class="td_right"><input type="password" name="password" class="fillet" placeholder="请输入密码"></td>
            </tr>
            <tr>
                <td class="td_left"><label for="confirmPassword">确认密码</label></td>
                <td class="td_right"><input type="password" name="confirmPassword" class="fillet" placeholder="请重新输入密码"></td>
            </tr>
            <tr>
                <td class="td_left"><label for="name">姓名</label></td>
                <td class="td_right"><input type="text" name="name" class="fillet" placeholder="请输入姓名"></td>
            </tr>
            <tr>
                <td class="td_left"><label>性别</label></td>
                <td class="td_right">
                    <input type="radio" name="gender" value="male">男
                    <input type="radio" name="gender" value="female">女
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center"><input type="submit" id="btn_sub" value="注册"></td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    function checkUsername(){
        var username = document.getElementById("username").value;
        if (username == "") {
            alert("用户名不能为空");
            return false;
        }
        if (username.length < 4 || username.length > 16) {
            alert("长度4-16个字符");
            return false;
        }
        return true;
    }

    function checkPassword(){
        var password = document.getElementById("password").value;
        if (password == "") {
            alert("密码不能为空");
            return false;
        }
        if (password.length < 4 || password.length > 16) {
            alert("密码长度为4-16位");
            return false;
        }
        return true;
    }

    function checkConfirmPassword(){
        var password = document.getElementById("password").value;
        var confirmPassword = document.getElementById("confirmPassword").value;
        if (confirmPassword == "") {
            alert("确认密码不能为空");
            return false;
        }
        if (password != confirmPassword) {
            div.innerHTML = "密码不一致";
            alert("密码不一致");
            return false;
        }
        return true;
    }

    function checkConfirmPassword(){
        var password = document.getElementById("password").value;
        var confirmPassword = document.getElementById("confirmPassword").value;
        if (confirmPassword == "") {
            alert("确认密码不能为空");
            return false;
        }
        if (password != confirmPassword) {
            alert("密码不一致");
            return false;
        }
        return true;
    }

    function checkName(){
        var name = document.getElementById("name").value;
        if (name == "") {
            alert("姓名不能为空");
            return false;
        }
        return true;
    }

    function checkGender(){
        var gender = document.getElementsByName("gender");
        var isCheched = false;
        for(i = 0; i < gender.length; i++) {
            if(gender[i].checked) {
                isCheched = true;
            }
        }
        if (!isCheched) {
            alert("性别不能为空");
            return false;
        }
        return true;
    }

    function check(){
        if(checkUsername() && checkPassword() && checkConfirmPassword() && checkName() && checkGender()) {
            alert("提交成功");
            return true;
        } else {
            return false;
        }
    }
</script>
</body>
</html>